<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8">
        <title>更新页面</title>
        <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
        <link rel="stylesheet" href="/app/admin/component/jsoneditor/css/jsoneditor.css" />
        <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
        
    </head>
    <body>

    <div class="layui-progress layui-progress-big" lay-showPercent="yes" lay-filter="progress">
        <div class="layui-progress-bar layui-bg-blue" lay-percent="0%"></div>
    </div>

        <script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
        <script src="/app/admin/component/pear/pear.js"></script>
        <script src="/app/admin/component/jsoneditor/jsoneditor.js"></script>
        <script src="/app/admin/admin/js/permission.js"></script>
        <script src="/app/admin/admin/js/functions.js"></script>
        <script src="/app/admin/admin/js/md5.js"></script>
        
        <script>
            // 相关接口
            const PRIMARY_KEY = "id";
            const REQUESTID = layui.url().search['requestid'];
            const PROGRESS_API = "/app/admin/plan/part/getprogress" + location.search;

            layui.use(['element',"popup","common"], function() {
                $ = layui.$;
                let common = layui.common;
                let element = layui.element;
                var n = 0, times = 0, timer = setInterval(function(){
                    times++;
                    if(times>7200){
                        return layer.alert('已经过去两个小时,生成超时',function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        });
                    }
                    $.ajax({
                        url: PROGRESS_API,
                        dataType: "json",
                        type: "post",
                        async: true,
                        headers: get_header({"requestid": REQUESTID}),
                        success: function (res) {
                            if (res.code) {
                                clearInterval(timer);
                                return layer.alert(res.msg,function () {
                                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                                });
                            } else {
                                n = parseInt(res.data.progress);
                                if (n >= 100) {
                                    n = 100;
                                    clearInterval(timer);
                                    setTimeout(function () {
                                        parent.refreshTable();
                                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                                    },1000)

                                }else if(n<0){
                                    clearInterval(timer);
                                    layer.alert(res.data.error??'生成失败',function () {
                                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                                    });
                                }
                                element.progress('progress', n + '%');
                            }
                        }
                    });
                }, 300+Math.random()*1000);
            })

        </script>

    </body>

</html>
